import { req_song_info,req_album_song,req_mv,req_special_songList,new_song_list} from "@/api";

const state = {

    song:{},

    album_song:{},

    mv_play:{},

    special_songList:{},

    new_song:{},
    
    
};
const getters = {

};
const mutations = {
    SONG(state,song){
        state.song=song
    },
    ALBUM_SONG(state,data){
        state.album_song=data
    },
    MV(state,data){
        state.mv_play=data
    },
    SPECIAL_SONG(state,data){
        state.special_songList=data
    },
    NEW_SONG(state,data){
        for(var i in data.info){
            data.info[i].album_sizable_cover=data.info[i].album_sizable_cover.replace('/{size}/','/')
            data.info[i].filename=data.info[i].filename.split('-')
        }
        state.new_song=data
    },
};
const actions = {
    //歌手歌曲列表
    async song_info({commit},{hash,ablumid,albumaudioid}){
        let result=await req_song_info(hash,ablumid,albumaudioid)
        let result_i=JSON.parse(result.slice(45,-2))
        if(result_i.err_code==0){
            commit('SONG',result_i.data)
        }else{
            return Promise.reject(new Error('faile'))
        }
    },
    //专辑歌曲列表
    async album_song({commit},ablumid){
        let result=await req_album_song(ablumid)
        let a=JSON.parse(result.slice(23,-21))
        console.log(a)
        if(a.status==1){
            commit('ALBUM_SONG',a.data)

        }else{
            return Promise.reject(new Error('faile'))
        }
    },
    //歌单歌曲列表
    async special_song({commit},specialid){
        let result=await req_special_songList(specialid)
        // let a=JSON.parse(result.slice(23,-21))
        // console.log(result)
        if(result.status==1){
            commit('SPECIAL_SONG',result.data)

        }else{
            return Promise.reject(new Error('faile'))
        }
    },
    //mv播放数据
    async mv_play({commit},hash){
        let result=await req_mv(hash)
        console.log(hash)
        console.log(result)
        if(result.status==1){
            commit('MV',result.mvdata)

        }else{
            return Promise.reject(new Error('faile'))
        }
    },
    //新歌列表
    async new_song({commit},{pagesize,type,page}){
        let a=await new_song_list(pagesize,type,page)
        let result=JSON.parse(a.slice(23,-21))
        if(result.status==1){
            commit('NEW_SONG',result.data)
        }else{
            return Promise.reject(new Error('faile'))
        }
    },

};
const modules = {

};

export default {
    state,
    getters,
    mutations,
    actions,
    modules
}